using System;
using System.Collections.Generic;
using PluginFrame;

namespace PcrExperimentProject
{
	[Serializable]
	public class AllelePcrExperimentProject : AbsolutePcrExperimentProject
	{
		public AllelePcrExperimentProject(IApplication app, List<bool> isChannelUsed)
			: this(app)
		{
		}

		public AllelePcrExperimentProject(IApplication app)
			: base(app)
		{
			mSystemType = PcrSystemType.Allele;
		}

		protected override void AddNewProjectTarget(string targetName, IProjectItem projectItem, int targetIndex)
		{
			IAnalysisParameterConfiguration analysisParameterConfiguration = mConfigurationService.CreateAlleleAnalysisParameterConfiguration(targetName, this) as IAnalysisParameterConfiguration;
			analysisParameterConfiguration.ProjectProperty = null;
			projectItem.TubeAnalysisParameterConfiguration.Add(analysisParameterConfiguration);
		}

		public override IProjectItem CreateProjectItem(int index, string name, int tubeCount)
		{
			IProjectItem projectItem = null;
			if (mProjectItems[index] == null)
			{
				projectItem = new AlleleProjectItem(name);
				projectItem.Dye = mChannelConfigurations[index].Content;
				projectItem.ChannelConfiguration = mChannelConfigurations[index];
				projectItem.AnalysisParameterConfiguration = mConfigurationService.CreateAlleleAnalysisParameterConfiguration(name, this) as IAnalysisParameterConfiguration;
				if (string.IsNullOrEmpty(name))
				{
					projectItem.TubeAnalysisParameterConfiguration = new List<IAnalysisParameterConfiguration> { projectItem.AnalysisParameterConfiguration };
				}
				else
				{
					projectItem.TubeAnalysisParameterConfiguration = new List<IAnalysisParameterConfiguration>();
					projectItem.TubeMeltingAnalysisParameterConfiguration = new List<IAnalysisParameterConfiguration>();
					string[] array = name.Split(new string[1] { "," }, StringSplitOptions.None);
					for (int i = 0; i < tubeCount; i++)
					{
						AddNewProjectTarget(array[i], projectItem, i);
					}
				}
				mProjectItems[index] = projectItem;
			}
			else
			{
				ChangeProjectItemName(index, name);
				projectItem = mProjectItems[index];
				string[] array2 = name.Split(new string[1] { "," }, StringSplitOptions.None);
				if (tubeCount < projectItem.TubeAnalysisParameterConfiguration.Count)
				{
					for (int j = 0; j < tubeCount; j++)
					{
						projectItem.TubeAnalysisParameterConfiguration[j].ProjectName = array2[j];
						projectItem.TubeMeltingAnalysisParameterConfiguration[j].ProjectName = array2[j];
					}
					projectItem.TubeAnalysisParameterConfiguration.RemoveRange(tubeCount, projectItem.TubeAnalysisParameterConfiguration.Count - tubeCount);
					projectItem.TubeMeltingAnalysisParameterConfiguration.RemoveRange(tubeCount, projectItem.TubeMeltingAnalysisParameterConfiguration.Count - tubeCount);
				}
				else
				{
					for (int k = 0; k < projectItem.TubeAnalysisParameterConfiguration.Count; k++)
					{
						projectItem.TubeAnalysisParameterConfiguration[k].ProjectName = array2[k];
						if (projectItem.TubeMeltingAnalysisParameterConfiguration != null && projectItem.TubeMeltingAnalysisParameterConfiguration.Count > 0)
						{
							projectItem.TubeMeltingAnalysisParameterConfiguration[k].ProjectName = array2[k];
						}
					}
					for (int l = projectItem.TubeAnalysisParameterConfiguration.Count; l < tubeCount; l++)
					{
						AddNewProjectTarget(array2[l], projectItem, l);
					}
				}
			}
			return projectItem;
		}
	}
}
